add api wx_jsapi_signature_api

Brightcells 9 anos atrás
pai
commit
8f43551640
8 arquivos alterados com 50 adições e 1 exclusões
  1. 6 0
      api/urls.py
  2. 1 1
      group/views.py
  3. 0 0
      wechat/__init__.py
  4. 4 0
      wechat/admin.py
  5. 0 0
      wechat/migrations/__init__.py
  6. 4 0
      wechat/models.py
  7. 4 0
      wechat/tests.py
  8. 31 0
      wechat/views.py

+ 6 - 0
api/urls.py

@@ -8,6 +8,7 @@ from message import views as message_views
8 8
 from operation import views as op_views
9 9
 from pay import views as pay_views
10 10
 from photo import views as photo_views
11
+from wechat import views as wechat_views
11 12
 
12 13
 
13 14
 # 帐户相关
@@ -90,6 +91,11 @@ urlpatterns += [
90 91
     url(r'^wx/notify_url$', pay_views.wx_notify_url_api, name='wx_notify_url_api'),  # 支付异步通知回调地址
91 92
 ]
92 93
 
94
+# 分享相关
95
+urlpatterns += [
96
+    url(r'^wx/jsapi_signature$', wechat_views.wx_jsapi_signature_api, name='wx_jsapi_signature_api'),  # jsapi_signature
97
+]
98
+
93 99
 # 首页相关
94 100
 urlpatterns += [
95 101
     url(r'^pai2/home$', group_views.pai2_home_api, name='pai2_home_api'),  # 首页信息

+ 1 - 1
group/views.py

@@ -1013,7 +1013,7 @@ def lensman_photo_bought(request):
1013 1013
 
1014 1014
 def group_photo_detail(request, photo_id):
1015 1015
     photo = GroupPhotoInfo.objects.get(pk=photo_id)
1016
-    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url})
1016
+    return render(request, 'photo/photo_detail.html', {'photo_url': photo.photo_url, 'api_domain': settings.API_DOMAIN})
1017 1017
 
1018 1018
 
1019 1019
 def group_detail(request, group_id):

+ 0 - 0
wechat/__init__.py


+ 4 - 0
wechat/admin.py

@@ -0,0 +1,4 @@
1
+from django.contrib import admin
2
+
3
+
4
+# Register your models here.

+ 0 - 0
wechat/migrations/__init__.py


+ 4 - 0
wechat/models.py

@@ -0,0 +1,4 @@
1
+from django.db import models
2
+
3
+
4
+# Create your models here.

+ 4 - 0
wechat/tests.py

@@ -0,0 +1,4 @@
1
+from django.test import TestCase
2
+
3
+
4
+# Create your tests here.

+ 31 - 0
wechat/views.py

@@ -0,0 +1,31 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import time
4
+
5
+import shortuuid
6
+from django.conf import settings
7
+from django.http import HttpResponse
8
+from wechatpy import WeChatClient
9
+
10
+
11
+r = settings.REDIS_CACHE
12
+WECHAT = settings.WECHAT
13
+JSAPI = WECHAT.get('JSAPI', {})
14
+
15
+
16
+def wx_jsapi_signature_api(request):
17
+    url = request.GET.get('url', '')
18
+    callback = request.GET.get('callback', '')
19
+
20
+    nonceStr, timestamp = shortuuid.uuid(), int(time.time())
21
+
22
+    client = WeChatClient(JSAPI['appID'], JSAPI['appsecret'])
23
+    ticket = client.jsapi.get_jsapi_ticket()
24
+    signature = client.jsapi.get_jsapi_signature(nonceStr, ticket, timestamp, url)
25
+
26
+    return HttpResponse('{}({})'.format(callback, {
27
+        'appId': JSAPI['appID'],
28
+        'noncestr': nonceStr,
29
+        'timestamp': timestamp,
30
+        'signature': signature,
31
+    }))